﻿Imports System.IO

Public Class VisordeLogs
    Dim steam As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam", "InstallPath", Nothing)
    Dim rutaarma As String = steam & "\steamapps\common\Arma 3"
    Dim esusservera3 As String = rutaarma & "\EsusServerA3" & "\" & Form1.ComboBox1.SelectedItem.ToString
    Private Sub Visordelogs_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim steam As String = Nothing
        Dim rutaarma As String = Nothing
        Dim esusservera3 As String = Nothing
        If CheckBox1.Checked = True Then
            Timer1.Interval = 2000 '3 seconds
            Timer1.Enabled = True
        Else
            Timer1.Stop()
            Timer1.Enabled = False
        End If

        Call leerlog()
    End Sub
    Sub leerlog()
        Try
            Dim leido As String = Nothing
            Dim dirinfo As DirectoryInfo

            Dim allFiles() As FileInfo

            dirinfo = New DirectoryInfo(esusservera3)

            allFiles = dirinfo.GetFiles("*.log")

            Array.Sort(allFiles, New clsCompareFileInfo)

            For Each fl As FileInfo In allFiles

                leido = fl.FullName.ToString()
            Next

            Dim LogFileStream As FileStream
            Dim LogFileReader As StreamReader

            LogFileStream = New FileStream(leido, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
            LogFileReader = New StreamReader(LogFileStream)
            RichTextBox1.Text = LogFileReader.ReadToEnd()
            LogFileReader.Close()
            LogFileStream.Close()
            RichTextBox1.SelectionStart = RichTextBox1.TextLength
            RichTextBox1.ScrollToCaret()
        Catch ex As Exception

        End Try
       
    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            Timer1.Interval = 2000 '3 seconds
            Timer1.Enabled = True
        Else
            Timer1.Stop()
            Timer1.Enabled = False
        End If
        My.Settings.refrescarlogs = CheckBox1.CheckState
        My.Settings.Save()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Call leerlog()
    End Sub

    Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged

    End Sub
End Class